package com.atguigu.serein.controller;

import com.atguigu.serein.bean.User;
import com.atguigu.serein.service.UserService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * @author SeRein
 */
@Slf4j
@Controller
public class TableController {

    @Autowired
    UserService userService;

    @GetMapping("/dynamic_table")
    public String dynamic_table(@RequestParam(value = "pn", defaultValue = "1") Integer pn, Model model) {

        List<User> list = userService.list();

        //model.addAttribute("users", list);

        //查询分页数据
        Page<User> userPage = new Page<>(pn, 2);

        //分页查询的结果
        Page<User> page = userService.page(userPage, null);

        log.info("总记录条数: " + page.getTotal());
        log.info("总页数: " + page.getPages());


        model.addAttribute("page", page);

        return "table/dynamic_table";
    }


}
